﻿#region Librerias

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ESF.Web.Pages;
using ESF.SSO.Core.Entities;

#endregion


public partial class Location_EditLocation : UserControl
{
	#region Carga Inicial
	
	protected void Page_Load(object sender, EventArgs e)
	{
		
	}
	
	#endregion
	
	
	#region Funciones
	
	public void Clear ()
	{
		txtCountryName.Text = string.Empty;
		txtAddress.Text = string.Empty;
		txtCellPhone.Text = string.Empty;
		txtCityName.Text = string.Empty;
		txtHomePhone.Text = string.Empty;
	}
	
	#endregion
	

	#region IEditLocationViewer Members

	public bool EnableValidators
	{
		set
		{
			rfvtxtAddress.Enabled = value;
			rfvtxtCityName.Enabled = value;
			rfvtxtCountryName.Enabled = value;
			rfvUserHomePhone.Enabled = value;
		}
	}
	
	
	private int? ItemID
	{
		set
		{
			ViewState ["ID"] = value;
		}
		get
		{
			if (ViewState ["ID"] == null)
			{
				return null;
			}
			
			return Convert.ToInt32 (ViewState ["ID"]);
		}
	}
	
	
	public Location Location
	{
		get
		{
			return new Location ()
			{
				ID = ItemID,
				Name = "Principal",
				Country = new ESF.General.Entity.BasicReference () { Name = txtCountryName.Text },
				City = new ESF.General.Entity.BasicReference () { Name = txtCityName.Text },
				PhoneNumber = txtHomePhone.Text,
				CellPhoneNumber = txtCellPhone.Text,
				Address = txtAddress.Text
			};
		}
		set
		{
			if (value == null)
			{
				Clear ();
			}
			else
			{
				ItemID = value.ID;
			
				if (value.Country != null) { txtCountryName.Text = value.Country.Name; }
				if (value.City != null) { txtCityName.Text = value.City.Name; }
				
				txtHomePhone.Text = value.PhoneNumber;
				txtCellPhone.Text = value.CellPhoneNumber;
				txtAddress.Text = value.Address;
			}
		}
	}

	#endregion
}